import * as Cesium from "cesium";
import "cesium/Build/Cesium/Widgets/widgets.css";

window.CESIUM_BASE_URL = import.meta.env.VITE_APP_CESIUM;

let viewer;

export const initCesium = async () => {
    await buildViewer();
    return viewer;
}


// ===== 点位加载 =====
const buildViewer = () => {
    Cesium.Ion.defaultAccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI0NTI3OGI2Ni05YmJhLTRlMTYtYjdiNC1hM2E5ZjI1MGYxZmIiLCJpZCI6MTQ0NTcxLCJpYXQiOjE3MDMxNTQ2MzZ9.-ab5sCTIXoyCUMMGv35NQBbR0h7pxsxu78D3AfCVTek";

    viewer = new Cesium.Viewer('cesiumContainer', {
        animation: false,
        baseLayerPicker: true,
        fullscreenButton: false,
        vrButton: false,
        geocoder: false,
        homeButton: true, // 首页，点击之后将视图跳转到默认视角
        infoBox: false,
        sceneModePicker: false,
        selectionIndicator: false,
        timeline: false,
        navigationHelpButton: false,
        navigationInstructionsInitiallyVisible: false,
        terrainProvider: Cesium.createWorldTerrainAsync(),
        scene3DOnly: true,
        // 高德影像地形地图：
        imageryProvider: new Cesium.UrlTemplateImageryProvider({
            url: "https://webst02.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}",
        })
    });
    // 隐藏logo
    viewer._cesiumWidget._creditContainer.style.display = "none";
}


